package cn.iocoder.yudao.module.exam.dal.mysql.question;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.exam.dal.dataobject.question.QuestionDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.exam.controller.admin.question.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 试题 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface QuestionMapper extends BaseMapperX<QuestionDO> {

    default PageResult<QuestionDO> selectPage(QuestionPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<QuestionDO>()
                .eqIfPresent(QuestionDO::getBankId, reqVO.getBankId())
                .eqIfPresent(QuestionDO::getQuestionText, reqVO.getQuestionText())
                .eqIfPresent(QuestionDO::getQuestionType, reqVO.getQuestionType())
                .eqIfPresent(QuestionDO::getDifficultyLevel, reqVO.getDifficultyLevel())
                .eqIfPresent(QuestionDO::getQuestionUrl, reqVO.getQuestionUrl())
                .betweenIfPresent(QuestionDO::getCreateTime, reqVO.getCreateTime())
                .inSql(StringUtils.isEmpty(reqVO.getBankName()),QuestionDO::getBankId,"select id from exam_bank where name like '%"+reqVO.getBankName()+"%'").orderByDesc(QuestionDO::getId));
    }

    IPage<QuestionRespVO>  selectVoPage(IPage<QuestionRespVO> mpPage, @Param("vo") QuestionPageReqVO reqVO);

}